﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using Clipping.Infrastructure.Models;

namespace ClippingMaster
{
    public class SearchObjectViewModel:GalaSoft.MvvmLight.ViewModelBase
    {
        public event Action<KeywordInfo> OnKeywordSearch;

        public SearchObjectViewModel()
        {
            initCommands();
        }

        private void initCommands()
        {
  
            this.SearchCommand = new GalaSoft.MvvmLight.Command.RelayCommand(search);
        }

        private void search()
        {

            if (string.IsNullOrEmpty(this.keyword))
                return;

            var handler = this.OnKeywordSearch;
            if (handler != null)
            {
                handler(new KeywordInfo() {  Keyword= this.keyword, SearchPeriod= SearchPeriod.全部时间, SearchType= SearchType.SearchInContent});

            }
        }

        private string keyword;

        public string Keyword
        {
            get { return keyword; }
            set 
            {
                if (this.keyword == value)
                    return;
                keyword = value;
                RaisePropertyChanged(() => this.Keyword);
            }
        }

        public ICommand SearchCommand { get; set; }
        
    }
}
